{% extends "oa/base.html" %}
{% load i18n static %}
{% block title %} 生产批次成本统计 {% endblock %}
{% block this_css %}
    <style>
        tbody > tr > td {
            white-space: nowrap
        }
    </style>
{% endblock %}
{% block content %}
    <section class="panel">
        <div class="panel-body">
            <form method="get" action="{{ request.path }}" class="form-inline">
                <div class="form-group">
                    <label for="date_before">统计截止日期:</label>
                    <input type="text" class="form-control" name="date_before" value="{{ request.GET.date_before }}"
                           id="date_before" placeholder="yyyy-mm-dd" data-date-format="yyyy-mm-dd">
                </div>
                <div class="form-group">
                    <label for="q">搜索:</label>
                    <input type="text" class="form-control" name="q" value="{{ request.GET.q }}" id="q">
                </div>
                <button type="submit" class="btn btn-info">重新统计</button>
                <a href="?update_act_volume=true"><span type="submit" class="btn btn-default">更新出酒率</span></a>
                <a target="_blank" href="?excel=1&date_before={{ request.GET.date_before }}&q={{ request.GET.q }}"><span type="submit" class="btn btn-default">导出EXCEL</span></a>
            </form>
        </div>
    </section>
    <section class="panel">
        <div class="panel-body table-responsive">
            <table class="table table-striped table-bordered table-responsive">
                <thead>
                <tr>
                    <th colspan="15"><h3>砖巷科技生产成本统计</h3></th>
                </tr>
                <tr>
                    <th>投料日期</th>
                    <th>截止日期</th>
                    <th>酒款</th>
                    <th>酿造批次</th>
                    <th>状态</th>
                    <th>投量（L）</th>
                    <th>产量（L）</th>
                    <th>已灌装量（L）</th>
                    <th>理论出酒率</th>
                    <th>实际出酒率</th>
                    <th class="text-center">原料总价（元）</th>
                    <th class="text-center">加工费（元）</th>
                    <th class="text-center">酒液总成本（元）</th>
                    <th class="text-center">理论酒液成本（元/L）</th>
                    <th>灌装明细</th>
                    <th class="text-center">包材总价（元）</th>
                    <th class="text-center">酒液+包材总额（元）</th>
                    <th class="text-center">剩余酒液成本（元）</th>
                </tr>
                </thead>
                <tbody>
                {% for pb in data.product_batches %}
                    <tr>
                        <td>{{ pb.start_date }}</td>
                        <td>{{ pb.finish_date|default_if_none:'' }}</td>
                        <td>{{ pb.product_name }}</td>
                        <td><a href="{% url 'page:product_batch_cost' pb.pk %}" target="_blank">{{ pb.batch_code }}</a></td>
                        <td>{{ pb.product_state }}</td>
                        <td>{{ pb.total_volume }}</td>
                        <td>{{ pb.est_volume }}</td>
                        <td>{{ pb.act_volume|floatformat:"1" }}</td>
                        <td>{{ pb.est_product_ratio|floatformat:"2" }} %</td>
                        <td>{{ pb.act_product_ratio|floatformat:"2" }} %</td>
                        <td class="text-right">{{ pb.total_material_costs|floatformat:"2" }}</td>
                        <td class="text-right">{{ pb.total_processing_costs|floatformat:"2" }}</td>
                        <td class="text-right">{{ pb.total_production_cost|floatformat:"2" }}</td>
                        <td class="text-right">{{ pb.est_material_cost_per_liter|floatformat:"4" }}</td>
                        <td>
                            <ul>{% for p in pb.packs %}
                                <li>
                                    <p>
                                        {{ p.date|date:'Y-m-d' }} {{ p.name }} <br>
                                        (数量：{{ p.pack_amount }}, 包材成本：{{ p.pack_cost|floatformat:"4" }} 元，
                                        <b>均摊成本：{{ p.est_per_pack_cost|floatformat:"4" }} 元</b>)
                                    </p>
                                </li>{% endfor %}
                            </ul>
                            <a href="{% url 'page:product_batch_cost' pb.pk %}" target="_blank">查看原料明细</a>
                        </td>
                        <td class="text-right">{{ pb.total_pack_costs|floatformat:"2" }}</td>
                        <td class="text-right">{{ pb.total_costs|floatformat:"2" }}</td>
                        <td class="text-right">{{ pb.total_left_value|floatformat:"2" }}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </section>
{% endblock %}